function onLoad(pagedata) {
	var doc = pagedata.originalTarget;
	if (pagedata.originalTarget.nodeName == "#document") { // ok, it's a real page, let's do our magic
		var text = doc.evaluate("/html/head/title",doc,null,XPathResult.STRING_TYPE,null).stringValue;
		alert(text);
	}			
}


function mainTask() {
}

mainTask.prototype = {
	run : function() {	
		try {
			var browser = document.getElementById('browser');
			var vbox = document.createElement('vbox');
			vbox.setAttribute('hidden', 'false');
			vbox.setAttribute('id', 'testvbox');
			vbox.setAttribute('height', '500');
			vbox.setAttribute('width', '300');
			var iframe = document.createElement("iframe");		
			iframe.setAttribute('type','content');
			iframe.setAttribute('src','');
			iframe.setAttribute('name','testiframe');
			iframe.setAttribute('id','testiframe');
			iframe.setAttribute('hidden','false');
			iframe.setAttribute('height','400');
			browser.appendChild(iframe);
			//vbox.appendChild(iframe);
			iframe.style.height = "100px";
			//alert(1);
			iframe.webNavigation.allowAuth = true;
			iframe.webNavigation.allowImages = false;
			iframe.webNavigation.allowJavascript = true;
			iframe.webNavigation.allowMetaRedirects = true;
			iframe.webNavigation.allowPlugins = false;
			iframe.webNavigation.allowSubframes = false;
			iframe.addEventListener("DOMContentLoaded", onLoad, true);	
			iframe.webNavigation.loadURI('http://google.com',Components.interfaces.nsIWebNavigation,null,null,null);
		} catch (err) {
			Components.utils.reportError(err);
		}
	},
	QueryInterface: function(iid) {
		if (iid.equals(Components.interfaces.nsIRunnable) ||
				iid.equals(Components.interfaces.nsISupports)) {
			return this;
		}
		throw Components.results.NS_ERROR_NO_INTERFACE;
	}			
}
			

var main = Components.classes["@mozilla.org/thread-manager;1"].getService().mainThread;
main.dispatch(new mainTask(), main.DISPATCH_NORMAL);	